// SpringTail : Simple Logging Abstraction block
// Copyright (c) 2008 Michael Saunders <mike@mikesaunders.com>
// All rights reserved.
// Released under Apache License 2.0 <www.apache.org/licenses>
// 
using System;
using NUnit.Framework;
using SpringTail;

namespace TestSpringTail
{
	[TestFixture]
	public class TestLogMessage
	{
		#region Test Constructors
		[Test]
		public void Test_Constructor_does_not_throw_for_null_loggerName()
		{
			new LogMessage(LogLevel.Debug, null, this, "message", new object());
		}

		[Test]
		public void Test_Constructor_does_not_throw_for_empty_loggerName()
		{
			new LogMessage(LogLevel.Debug, string.Empty, this, "message", new object());
		}

		[Test]
		public void Test_Constructor_does_not_throw_for_null_loggerOwner()
		{
			new LogMessage(LogLevel.Debug, "name", null, "message", new object());
		}

		[Test]
		public void Test_Constructor_does_not_throw_for_null_message()
		{
			new LogMessage(LogLevel.Debug, "name", this, null, new object());
		}

		[Test]
		public void Test_Constructor_does_not_throw_for_empty_message()
		{
			new LogMessage(LogLevel.Debug, "name", this, string.Empty, new object());
		}

		[Test]
		public void Test_Constructor_does_not_throw_for_null_data()
		{
			new LogMessage(LogLevel.Debug, "name", this, "message", null);
		}

		[Test]
		[ExpectedException(typeof(ArgumentNullException))]
		public void Test_Constructor_throws_for_null_exception()
		{
			new LogMessage(LogLevel.Debug, "name", this, "message", new object(), null);
		}
		#endregion

		#region Test Properties
		[Test]
		public void Test_properties()
		{
			object data = new object();
			LogMessage message = new LogMessage(LogLevel.Debug, "name", this, "message", data);
			Assert.AreEqual(LogLevel.Debug, message.Level);
			Assert.AreEqual("name", message.LoggerName);
			Assert.AreSame(this, message.LoggerOwner);
			Assert.AreEqual("message", message.Message);
			Assert.AreSame(data, message.Data);
			Assert.IsNull(message.Exception);
		}

		[Test]
		public void Test_get_properties_including_exception_property()
		{
			object data = new object();
			Exception exception = new Exception();
			LogMessage message = new LogMessage(LogLevel.Error, "name", this, "message", data, exception);
			Assert.AreEqual(LogLevel.Error, message.Level);
			Assert.AreEqual("name", message.LoggerName);
			Assert.AreSame(this, message.LoggerOwner);
			Assert.AreEqual("message", message.Message);
			Assert.AreSame(data, message.Data);
			Assert.AreSame(exception, message.Exception);
		}
		#endregion
	}
}